package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.CurrentAffairs;
import com.sc.nft.entity.MallMemberEquity;
import com.sc.nft.entity.MallMemberEquityUseRecord;
import com.sc.nft.mapper.MallMemberEquityUseRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @Author：LiGen
 * @Package：com.sc.nft.dao
 * @Project：sc_metago
 * @name：MallMemberEquityTargetDao
 * @Date：2024/4/2 19:29
 * @Filename：MallMemberEquityTargetDao
 */
@Slf4j
@Repository
public class MallMemberEquityUseRecordDao extends ServiceImpl<MallMemberEquityUseRecordMapper, MallMemberEquityUseRecord> {

    public MallMemberEquityUseRecord getByOrderId(Long orderId) {
        return baseMapper.getByOrderId(orderId);
    }

    /**
     * 获取用户通过会员权益下单列表
     * @param memberId
     * @param mallMemberEquityTemplateId
     * @param userId
     * @return
     */
    public List<MallMemberEquityUseRecord> getByMallMemberEquityId(Long memberId,Long mallMemberEquityTemplateId, Long userId, Date startTime, Date endTim) {
        return baseMapper.getByMallMemberEquityId(memberId,mallMemberEquityTemplateId,userId,startTime,endTim);
    }

    public int checkUseCount(Long mallEquityId, Long userId, Date startTime, Date endTime) {
        return baseMapper.checkUseCount(mallEquityId,userId,startTime,endTime);
    }

    public boolean deleteById(Long id) {
        LambdaUpdateWrapper<MallMemberEquityUseRecord> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
        lambdaUpdateWrapper.eq(MallMemberEquityUseRecord::getId, id);
        return remove(lambdaUpdateWrapper);
    }
}
